﻿/*

BlockUIModule uses the jQuery BlockUI plug-in to disable access
to the grid while data operations are in progress. 

Author: MBH
DateAuthored: 8/2/09
*/

//Uses the BlockUI plug-in to disable access to 
function BlockUIModule() {
	var base = this;

	//Registers for events.
	base.initialize = function(liteGrid, options) {

		if (!$.blockUI) {
			console.error("BlockUI plug-in is not loaded, unable to use BlockUIModule.");
			return;
		}

		//We only care about data load events (for now).
		liteGrid.$el.bind("dataLoading", base.dataLoading);
		liteGrid.$el.bind("dataLoaded", base.dataLoaded);
		liteGrid.$el.bind("actionCancelled", base.actionCancelled);

		//Store references that will be needed later.
		base.liteGrid = liteGrid;
	}

	//Fired when a provider begins loading data.
	base.dataLoading = function() {
		base.liteGrid.wrapperDiv.block({ message: "Loading, please wait..." });
	}

	//Fired after data has been loaded.
	base.dataLoaded = function() {
		base.liteGrid.wrapperDiv.unblock();
	}

	// Fired when an action is cancelled
	base.actionCancelled = function(event) {
		var button = $("<input/>")
			.attr({ type: 'button', value: 'OK' })
			.click(function() { base.liteGrid.wrapperDiv.unblock(); return false; });
		
		var div = $('<div/>');
		div.text(event.message);
		div.append('<br/>').append(button);
		
		base.liteGrid.wrapperDiv.block({ message: div });
	}
}
